<?php 

require_once 'domain/User.php';
require_once(APPPATH.'libraries/MY_Model.php');

class M_user extends MY_Model {

	function M_user()
	{$suite_cert_cn;
		parent::MY_Model('users','user_id');
	}
	
	/*****************************************************
	 * GENERAL 
	 ****************************************************/

	protected function afromEntityToDb(User $user){
		$ret = array(
			'user_id'		=> $user->id,
			'user_nick' 	=> $user->nick,
			'user_login' 	=> $user->login ,
			'user_password' => $user->password,
			'user_created'	=> $this->getDateToDb($user->create_date),
			'suite_cert_cn'	=> $user->suite_cert_cn,
                        'is_admin'      => $user->is_admin
		);
		return $ret;
	}

	protected function afromDbToEntity(array $p_user){
		$u = new User();
		$u->id			= $p_user['user_id'];
		$u->nick		= $p_user['user_nick'];
		$u->login		= $p_user['user_login'];
		$u->password	= $p_user['user_password'];
		$u->create_date	= $this->getDateFromDb($p_user['user_created']);
		$u->suite_cert_cn = $p_user['suite_cert_cn'];
                $u->is_admin = $p_user['is_admin'];
		return $u;
	}

	/*****************************************************
	 * ACCESO A DATOS
	 ****************************************************/

	function getUserFromLogin($login){
		return $this->getByWhat('user_login',$login);
	}

	function create(User $user){
		$user->create_date = date_create();
		return parent::create($user);
	}

}

?>
